package com.example.behaviorpattern.iterator.impl;

import com.example.behaviorpattern.iterator.Iterator;


/**
 * 具体迭代器实现
 *
 * @author yaojianfeng
 */
public class ConcreteIterator implements Iterator {
    private final ConcreteAggregate aggregate;
    private int currentIndex = 0;

    public ConcreteIterator(ConcreteAggregate aggregate) {
        this.aggregate = aggregate;
    }

    @Override
    public boolean hasNext() {
        return currentIndex < aggregate.size();
    }

    @Override
    public Object next() {
        if (hasNext()) {
            return aggregate.get(currentIndex++);
        }
        return null;
    }
}